package com.jessechanrui.template.database.mybatisplus.service.impl;

import com.baomidou.dynamic.datasource.annotation.DS;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.jessechanrui.template.database.mybatisplus.entity.UserDO;
import com.jessechanrui.template.database.mybatisplus.mapper.UserMapper;
import com.jessechanrui.template.database.mybatisplus.service.IUserService;
import com.jessechanrui.template.database.mybatisplus.service.event.MsgEvent;
import org.springframework.context.event.EventListener;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class UserServiceImpl extends ServiceImpl<UserMapper, UserDO> implements IUserService {

    @DS("salve_1")
    @Override
    public List<UserDO> getList() {
        return this.getList();
    }

    @DS("master")
    @Override
    public int saveUser(UserDO userDO) {
        boolean save = this.save(userDO);
        if (save){
            return 1;
        }else{
            return 0;
        }
    }

    // 通过注解的方法
    @EventListener(MsgEvent.class)
    public void consumer(MsgEvent msgEvent) {
        System.out.println("@EventListener注解事件方式: " + msgEvent.getMessage());
    }
}
